home *** CD-ROM | disk | FTP | other *** search
- /* © 1988, Bowers Development Corp. */
- /* Miscellany.c */
-
- #include "Globals.h"
- #include "ResourceDefs.h"
-
- #include "Miscellany.h"
-
- /* global vars: */
- Boolean errorFlag;
-
-
- #define createTop 75
- #define createLeft 100
-
- /*----------*/
- void Acknowledge (alertID)
- short alertID;
- {
- short itemHit;
-
- InitCursor ();
- itemHit = StopAlert (alertID, nil);
- } /*Acknowledge*/
-
- /*----------*/
- Boolean Confirm (alertID)
- short alertID;
- {
- InitCursor ();
- return (CautionAlert (alertID, nil) == OK);
- } /*Confirm*/
-
- /*----------*/
- Boolean GetErrorMessage (OSErr resultCode,
- Str255 message);
- Boolean GetErrorMessage (resultCode, message)
- OSErr resultCode;
- Str255 message;
- {
- StringHandle msgHndl;
-
- msgHndl = (StringHandle) GetResource ('ErMs', -resultCode);
- if (msgHndl != nil) {
- BlockMove (&(**msgHndl), message, 256);
- return (true);
- } else {
- message [0] = 0;
- return (false);
- }
- } /*GetErrorMessage*/
-
- /*----------*/
- Boolean CheckOS (resultCode)
- OSErr resultCode;
- {
- Str255 message;
- Str255 errNum;
-
- if (resultCode == noErr) {
- return (true);
- } else {
- if (GetErrorMessage (resultCode, message)) {
- ParamText (message, "", "", "");
- } else { /*generic message*/
- if (!GetErrorMessage (0, message)) {
- BlockMove ("\pOS Error ", message, 10);
- }
- NumToString (resultCode, errNum);
- ParamText (message, errNum, "", "");
- }
- Acknowledge (IOErrorID);
- errorFlag = true;
- return (false);
- }
- } /*CheckOS*/
-
- /*----------*/
- Boolean FileExists (fName, vRefNum)
- Str255 fName;
- short vRefNum;
- {
- FInfo fileInfo;
-
- return (GetFInfo (fName, vRefNum, &fileInfo) == noErr);
- } /*FileExists*/
-
- /*----------*/
- Boolean CreateFile (sfInfo, prompt, suggestion, creator, fileType)
- SFReply *sfInfo;
- Str255 prompt;
- Str255 suggestion;
- OSType creator;
- OSType fileType;
- {
- Point dlgOrigin;
- Boolean okay;
-
- SetPt (&dlgOrigin, createLeft, createTop);
- SFPutFile (dlgOrigin, prompt, suggestion, nil, sfInfo);
- okay = sfInfo->good;
- if (okay) {
- if (FileExists (sfInfo->fName, sfInfo->vRefNum)) {
- okay = CheckOS (FSDelete (sfInfo->fName, sfInfo->vRefNum));
- }
- }
- if (okay) {
- okay = CheckOS (Create (sfInfo->fName, sfInfo->vRefNum, creator, fileType));
- }
- return (okay);
- } /*CreateFile*/
-
- /*----------*/
- void ScaleWindow (window, scaleSize)
- WindowPtr window;
- Boolean scaleSize;
- {
- Rect newBounds;
- Rect globalBounds;
- Rect origScreen;
- Rect curScreen;
- short height;
- short width;
-
- globalBounds = window->portBits.bounds;
- newBounds = window->portRect;
- OffsetRect (&newBounds, -globalBounds.left, -globalBounds.top); /*LocalToGlobal*/
- SetRect (&origScreen, 0, 20, 512, 342);
- curScreen = screenBits.bounds;
- curScreen.top = MBarHeight;
- height = newBounds.bottom - newBounds.top;
- width = newBounds.right - newBounds.left;
- MapRect (&newBounds, &origScreen, &curScreen);
- if (scaleSize) {
- SizeWindow (window, newBounds.right - newBounds.left,
- newBounds.bottom - newBounds.top, true);
- } else {
- newBounds.top = newBounds.bottom - height;
- newBounds.left = newBounds.right - width;
- }
- MoveWindow (window, newBounds.left, newBounds.top, false);
- } /*ScaleWindow*/
-
- /*----------*/
- void DrawClippedGrow (x, y)
- short x;
- short y;
- {
- RgnHandle saveClip;
- Rect growRect;
- Rect portRect;
-
- saveClip = NewRgn ();
- GetClip (saveClip);
- portRect = thePort->portRect;
- if (x >= 0) {
- x = portRect.left + x;
- } else {
- x = portRect.right + x;
- }
- if (y >= 0) {
- y = portRect.top + y;
- } else {
- y = portRect.bottom + y;
- }
- SetRect (&growRect, x, y, portRect.right, portRect.bottom);
- ClipRect (&growRect);
- DrawGrowIcon (thePort);
- SetClip (saveClip);
- DisposeRgn (saveClip);
- } /*DrawClippedGrow*/
-
- /*----------*/
- void DoRadioMenu (menu, firstItem, lastItem, itemNr)
- MenuHandle menu;
- short firstItem;
- short lastItem;
- short itemNr;
- {
- short i;
-
- for (i = firstItem; i <= lastItem; i++) {
- CheckItem (menu, i, (i == itemNr));
- }
- } /*DoRadioMenu*/
-